function LevelPanel(x, y, w, h, td)
{
  var _x;
  var _y;
  var _root;
  var _width;
  var _height;
  var _td;
  var levelMovies;
  var levelMovieHeight;
  var lPosition;
  var levelSpeed;
  var _animationTime;
  
  this._x = x;
  this._y = y;
  this._width = w;
  this._height = h;
  this._td = td;
  this.levelMovies = new Array();
  this.levelMovieHeight = 20;
  this.lPosition = 40;
}

LevelPanel.prototype.Init = function()
{
  this._root = new MovieClip();
  this._root.x = this._x;
  this._root.y = this._y;
  
  //dibujo el fondo
  this._root.DrawRectangle(0, 0, this._width, this._height, '#AAAAAA', 1);
  
  for (var i = 0; i < this._td.levels.length; i++)
  {
	var levelMovie = new MovieClip("L" + i, this._root);
	levelMovie.DrawRectangle(0, 0, this._width, this.levelMovieHeight, '#CCCCCC', 1);
	levelMovie.DrawLine(0, this.levelMovieHeight, this._width, this.levelMovieHeight, '#DEDEDE', 1);
	levelMovie.DrawString(5, 15, "L " + i, "#660000", false);
	levelMovie.y = i * this.levelMovieHeight;
	
	levelMovie._root.addEventListener("mouseup", Delegate.create(this, this.onLevelClick), false);
	
	this.levelMovies.push({"movie" : levelMovie, "index" : i});
  }
  
  this.updatePositions();
}

LevelPanel.prototype.updatePositions = function()
{
	for (var i = 0; i < this.levelMovies.length; i++)
	{
		this.levelMovies[i].movie.y = i * this.levelMovieHeight + this.lPosition;
	}
}

LevelPanel.prototype.Work = function()
{
	if (this.levelMovies.length > 0 && this._td.levelIndex >= 0)
	{
		if (this.lPosition <= 0) 
		{
			this.levelMovies[0].movie.Dispose();
			this.levelMovies.splice(0, 1);
			this.lPosition = this.levelMovieHeight;
		}
		else if (this._td.levelIndex + 1 > this.levelMovies[0].index) this.lPosition -= 4;
		else
		{
			var despY = ((new Date()).getTime() - this._animationTime.getTime()) * this.levelSpeed;
			this._animationTime = new Date();
			this.lPosition -= despY;
		}
		
		this.updatePositions();
	}
}

LevelPanel.prototype.onLevelClick = function()
{
	this._td.InitNextLevel();
	this.calculateLevelSpeed();
}

LevelPanel.prototype.calculateLevelSpeed = function()
{
	//calculo la velocidad de los paneles de los niveles.  pixeles por milisegundo
	this.levelSpeed = this.levelMovieHeight / this._td.levels[this._td.levelIndex].GetLevelTime();
	this._animationTime = new Date();
}

LevelPanel.prototype.toString = function()
{
  return "[LevelPanel]";
}